package General;

import java.sql.*;

import javax.swing.*;

import Database.*;
import Exception.*;

public class GeneralInformation
{
	private static MyTableModel courseLeftModel, examModel, studentModel, penaltyModel, assessmentModel;
	private static MyTableModel courseDescriptModel, boundCourseDescriptModel, penaltyDescriptModel, studentListModel;
	private static MyTableModel infoClassModel, myAccountModel;
	private static int idSelected, idExaminationLaunch;
	
	//////////		Student		//////////
	public static void createStudentModel(Connection connection) throws CheckDataException, LoadDriverException{
		studentModel = new StudentMgmt(connection).selectAllElements();
	
		//To test value in studentModel
		/*int cpt = 0;
		while(cpt < studentModel.getRowCount()){
		System.out.println(studentModel.getValueAt(cpt, 0));// -> student.id
		System.out.println(studentModel.getValueAt(cpt, 1));// -> student.firstname
		System.out.println(studentModel.getValueAt(cpt, 2));// -> student.lastname
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	public static void setInfoStudentModel(Connection connection, JTable table, int selectedRow) throws CheckDataException, LoadDriverException{
		studentModel = new StudentMgmt(connection).selectOneStudent((int)GeneralInformation.getStudentModel().getValueAt(selectedRow, 0));
		
		//To test value in studentModel
		/*int cpt = 0;
		while(cpt < studentModel.getRowCount()){
		System.out.println(studentModel.getValueAt(cpt, 0));// -> student.id
		System.out.println(studentModel.getValueAt(cpt, 1));// -> student.firstname
		System.out.println(studentModel.getValueAt(cpt, 2));// -> student.lastname
		System.out.println(studentModel.getValueAt(cpt, 3));// -> student.indexjava
		System.out.println(studentModel.getValueAt(cpt, 4));// -> classe.yearcode
		System.out.println(studentModel.getValueAt(cpt, 5));// -> classe.sectioncode
		System.out.println(studentModel.getValueAt(cpt, 6));// -> classe.groupletter
		System.out.println(studentModel.getValueAt(cpt, 7));// -> classe.id
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	public static void createStudentListModel(Connection connection, int id) throws CheckDataException, LoadDriverException{
		studentListModel = new ExaminationMgmt(connection).selectBoundStudents(id);}
	
	//////////		Assessment		//////////
	public static void createAssessmentDescriptModel(Connection connection, JTable table, int selectedRow) throws CheckDataException, LoadDriverException{
		assessmentModel = new AssessmentMgmt(connection).selectAllElements((int)table.getValueAt(selectedRow, 2));} //ATTENTION Change the table -> model
	
	//////////		Examination		//////////
	public static void createExamModel(Connection connection) throws CheckDataException, LoadDriverException{
		examModel = new ExaminationMgmt(connection).selectAllElements();
		
		//To test value in examModel
		/*int cpt = 0;
		while(cpt < examModel.getRowCount()){
		System.out.println(examModel.getValueAt(cpt, 0));// -> libelle
		System.out.println(examModel.getValueAt(cpt, 1));// -> datecreation
		System.out.println(examModel.getValueAt(cpt, 2));// -> id
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	public static void createExamSecondSessModel(Connection connection) throws CheckDataException, LoadDriverException{
		examModel = new ExaminationMgmt(connection).selectAllSecondSessElements();
		
		//To test value in examModel
		/*int cpt = 0;
		while(cpt < examModel.getRowCount()){
		System.out.println(examModel.getValueAt(cpt, 0));// -> libelle
		System.out.println(examModel.getValueAt(cpt, 1));// -> datecreation
		System.out.println(examModel.getValueAt(cpt, 2));// -> id
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	//////////		Account		//////////
	public static void initAccountModel(Connection connection) throws CheckDataException, LoadDriverException{
		myAccountModel = new AccountMgmt(connection).selectAllElements();
	
		//To test value in myAccountModel
		/*int cpt = 0;
		while(cpt < myAccountModel.getRowCount()){
		System.out.println(myAccountModel.getValueAt(cpt, 0));// -> firstname
		System.out.println(myAccountModel.getValueAt(cpt, 1));// -> lastname
		System.out.println(myAccountModel.getValueAt(cpt, 2));// -> id
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	public static void createAccountBoundCourses(Connection connection, JTable table, int selectedRow) throws CheckDataException, LoadDriverException{
		boundCourseDescriptModel = new AccountMgmt(connection).selectBoundCourses((Integer)table.getValueAt(selectedRow, 2));} //ATTENTION Change the table -> model
	
	//////////		Penalty		//////////
	public static void createPenaltyModel(Connection connection) throws CheckDataException, LoadDriverException{
		penaltyModel = new PenaltyMgmt(connection).selectAllElements();
		
		//To test value in penaltyModel
		/*for(int cpt = 0; cpt < penaltyModel.getRowCount(); cpt++){
		System.out.println(penaltyModel.getValueAt(cpt, 0)); // -> libelle
		System.out.println(penaltyModel.getValueAt(cpt, 1)); // -> datecreation
		System.out.println(penaltyModel.getValueAt(cpt, 2)); // -> id
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	public static void createPenaltyDescriptModel(Connection connection, JTable table, int selectedRow) throws CheckDataException, LoadDriverException{
		penaltyDescriptModel = new PenaltyMgmt(connection).selectRestOfInfo((int)GeneralInformation.getPenaltyModel().getValueAt(selectedRow, 2));
		
		//To test value in penaltyDescriptModel
		/*for(int cpt = 0; cpt < penaltyDescriptModel.getRowCount(); cpt++){
		System.out.println(penaltyDescriptModel.getValueAt(cpt, 0));// -> timecondition
		System.out.println(penaltyDescriptModel.getValueAt(cpt, 1));// -> percent
		System.out.println(penaltyDescriptModel.getValueAt(cpt, 2));// -> id
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	public static void createPenaltyDescriptModel(Connection connection, int id) throws CheckDataException, LoadDriverException{
		penaltyDescriptModel = new PenaltyMgmt(connection).selectRestOfInfo(id);}
	
	//////////		Course		//////////
	public static void createCourseFullModel(Connection connection) throws CheckDataException, OperationImpossibleException, LoadDriverException{
		courseLeftModel = new CourseMgmt(connection).selectAllCourses();}
	
	public static void createCourseDescriptModel(Connection connection, JTable table, int selectedRow) throws CheckDataException, LoadDriverException{
		courseDescriptModel = new CourseMgmt(connection).selectBoundStudents((int)(GeneralInformation.getCourseLeftModel().getValueAt(selectedRow, 3)));
		
		//To test value in courseDescriptModel
		/*for(int cpt = 0; cpt < courseDescriptModel.getRowCount(); cpt++){
		System.out.println(courseDescriptModel.getValueAt(cpt, 0)); // -> id
		System.out.println(courseDescriptModel.getValueAt(cpt, 1)); // -> firstname
		System.out.println(courseDescriptModel.getValueAt(cpt, 2)); // -> lastname
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	public static void createCourseLeftModel(Connection connection) throws CheckDataException, LoadDriverException{
		courseLeftModel = new CourseMgmt(connection).selectAllElements();
		
		//To test value in courseLeftModel
		/*int cpt = 0;
		while(cpt < courseLeftModel.getRowCount()){
		System.out.println(courseLeftModel.getValueAt(cpt, 0)); // -> lastname
		System.out.println(courseLeftModel.getValueAt(cpt, 1)); // -> libelle
		System.out.println(courseLeftModel.getValueAt(cpt, 2)); // -> accountid
		System.out.println(courseLeftModel.getValueAt(cpt, 3)); // -> courseid
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	public static void initClassRightModel(Connection connection) throws CheckDataException, LoadDriverException{
		infoClassModel = new CourseMgmt(connection).infoClass();
		
		//To test value in infoClassModel
		/*int cpt = 0;
		while(cpt < infoClassModel.getRowCount()){
		System.out.println(infoClassModel.getValueAt(cpt, 0)); // -> year
		System.out.println(infoClassModel.getValueAt(cpt, 1)); // -> section
		System.out.println(infoClassModel.getValueAt(cpt, 2)); // -> group
		System.out.println(infoClassModel.getValueAt(cpt, 3)); // -> id
		System.out.println("\n--------------------\n");cpt++;}*/
	}
	
	public static void createCourseTotalModel(Connection connection) throws CheckDataException, LoadDriverException{
		courseLeftModel = new CourseMgmt(connection).selectTotalCourses();}
	
	//Gettors
	public static MyTableModel getMyAccountModel(){return myAccountModel;}
	
	public static MyTableModel getCourseLeftModel(){return courseLeftModel;}
	public static MyTableModel getCourseDescriptModel(){return courseDescriptModel;}
	public static MyTableModel getBoundCourseDescriptModel(){return boundCourseDescriptModel;}
	public static MyTableModel getClassRightModel(){return infoClassModel;}
	
	public static MyTableModel getStudentModel(){return studentModel;}
	public static MyTableModel getStudentListModel(){return studentListModel;}
	
	public static MyTableModel getExamModel(){return examModel;}
	
	public static MyTableModel getPenaltyModel(){return penaltyModel;}
	public static MyTableModel getPenaltyDescriptModel(){return penaltyDescriptModel;}
	
	public static void setIdSelectedLeftTable(int idSelectedReceive){idSelected = idSelectedReceive;}
	public static int getIdSelectedLeftTable(){return idSelected;}
	
	public static void setIdExaminationLaunch(int idExaminationReceive){idExaminationLaunch = idExaminationReceive;}
	public static int getIdExaminationLaunch(){;return idExaminationLaunch;}
	
	public static MyTableModel getAssessmentModel(){return assessmentModel;}
}